package ccy.ccyknapsackbind;

import ccy.ccylibrary.utils.Method;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;

import java.util.List;

public class InventoryClick implements Listener {

    CcyKnapsackBind ccyKnapsackBind = CcyKnapsackBind.ccyKnapsackBind;

    @EventHandler
    public void onClick(InventoryClickEvent e){
        ItemStack currentItem = e.getCurrentItem();
        if(currentItem==null || currentItem.getItemMeta()==null || currentItem.getItemMeta().getLore()==null){
            return;
        }else if(currentItem.getItemMeta().getLore().contains(ccyKnapsackBind.getBindLore()) && !ccyKnapsackBind.getWhiteGuiList().contains(e.getInventory().getTitle())){
            e.setCancelled(true);
            Method.sendmessage(e.getWhoClicked(),ccyKnapsackBind.getMessage());
        }
    }

    @EventHandler
    public void onDrop(PlayerDropItemEvent event){
        List<String> lore = event.getItemDrop().getItemStack().getItemMeta().getLore();

        if(lore!=null && lore.contains(ccyKnapsackBind.getBindLore())){
            event.setCancelled(true);
            Method.sendmessage(event.getPlayer(),ccyKnapsackBind.getMessageDrop());
        }
    }
}
